package com.carnation.servlet;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.carnation.utils.Json;
import com.google.gson.Gson;

public class LogoutServlet extends HttpServlet{

	private static final long serialVersionUID = 1L;
	private Logger logger = Logger.getLogger(LogoutServlet.class);

	protected void doGet(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse){
		doPost(httpServletRequest, httpServletResponse);
	}
	
	protected void doPost(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse){
		Json json = new Json();
		String msg = null;
		String status = null;
		httpServletRequest.getSession().invalidate();
		msg = "成功退出登录";
		status ="200";
		json.setMsg(msg);
		json.setStatus(status);
		Gson gson = new Gson();
		httpServletResponse.setCharacterEncoding("UTF-8");
		try {
			httpServletResponse.getWriter().write(gson.toJson(json));
			httpServletResponse.getWriter().close();
		} catch (Exception e) {
			logger.error("退出登录失败",e);
		}
	}
}
